<?php include _include(ADMIN_PATH.'view/htm/header.inc.htm');?>

<div class="row">
    <div class="col-12">
        <div class="btn-group mb-3" role="group">
            <a role="button" class="btn btn-secondary active" href="<?php echo url('collection-list');?>">采集管理</a>
            <a role="button" class="btn btn-secondary" href="<?php echo url('collection-add');?>">添加采集</a>
        </div>
    </div>
</div>

<div class="row">
    <div class="col-lg-12">
        <div class="card">
            <div class="card-header">
                <ul class="nav nav-tabs card-header-tabs">
                    <li class="nav-item">
                        <a class="nav-link <?php if($statusCur===''){?>active<?php }?>" href="<?php echo url('collection-publist-'.$id);?>">全部</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link <?php if($statusCur===0){?>active<?php }?>" href="<?php echo url('collection-publist-'.$id.'-1-0');?>">未采集</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link <?php if($statusCur==1){?>active<?php }?>" href="<?php echo url('collection-publist-'.$id.'-1-1');?>">已采集</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link <?php if($statusCur==2){?>active<?php }?>" href="<?php echo url('collection-publist-'.$id.'-1-2');?>">已导入</a>
                    </li>
                </ul>
            </div>
            <div class="card-body">
                <form action="<?php echo url('collection-optionall');?>" method="post" id="form">
                    <input type="hidden" name="nodeid" value="<?php echo $id;?>" />
                <div class="table-responsive">
                    <table class="table" style="min-width: 800px">
                        <thead>
                            <tr>
                                <th width="60" class="text-center"><input type="checkbox" id="idcheck" /></th>
                                <!--<th width="50">ID：</th>-->
                                <th width="150">状态</th>
                                <th width="150">标题</th>
                                <th width="150">网址</th>
                                <th width="150">操作</th>
                            </tr>
                        </thead>
                        <tbody>
                        <?php foreach($lists as $val){ ?>
                        <span id="showpre_<?php echo $val['id']; ?>" style="display: none" name="" id="" cols="30" rows="10">
                            <?php
                                echo '<pre>';
                                $data = json_decode($val['data'], true);
                                if($data) {
                                    $data['content'] = htmlentities($data['content']);
                                    print_r($data);
                                } else {
                                    echo '还未采集该条数据';
                                }
                                echo '</pre>';
                            ?>
                        </span>
                        <tr>
                            <td class="text-center"><input type="checkbox" name="ids[]" value="<?php echo $val['id']; ?>" /></td>
                            <!--<td><?php //echo $val['id']; ?></td>-->
                            <td>
                                <?php
                                $status = array(0=>'未采集', '1'=>'已采集', '2'=>'已导入');
                                echo $status[$val['status']];
                                    ?>
                            </td>
                            <td><?php echo trim($val['title']); ?></td>
                            <td><?php echo trim($val['url']); ?></td>
                            <td onclick="showpre('showpre_<?php echo $val['id']; ?>');"><a href="javascript:void(0);">查看</a></td>
                        </tr>
                        <?php } ?>
                        </tbody>
                    </table>
                </div>
                <hr class="mt-0" />
                <div class="btn-group" role="group" aria-label="Basic example">
                    <button type="submit" name="option" value="delete" class="btn btn-danger option">删除</button>
                    <button type="submit" name="option" value="deleteall" class="btn btn-danger option">同时删除历史</button>
                    <?php if($statusCur === '' || $statusCur == 1){?>
                    <button type="submit" name="option" value="import" class="btn btn-info option">导入选中</button>
                    <button type="submit" name="option" value="importall" class="btn btn-info option">导入全部</button>
                    <?php }?>
                </div>
                    <!-- Modal -->
                    <div class="modal" id="importData" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                        <div class="modal-dialog modal-lg modal-dialog-centered" role="document">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <h5 class="modal-title" id="exampleModalLabel">导入数据</h5>
                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                        <span aria-hidden="true">&times;</span>
                                    </button>
                                </div>
                                <div class="modal-body">
                                    <div class="form-group row">
                                        <input type="hidden" id="importType" name="option" value="" />
                                        <label class="col-sm-2 form-control-label">选择版块：</label>
                                        <div class="col-sm-10">
                                            <div class="form-check form-check-inline">
                                                <?php if($forums){ foreach($forums as $val) {?>
                                                <label><input type="checkbox" class="form-check-input" value="<?php echo $val['fid'];?>" name="forumids[]" /><?php echo $val['name'];?></label>
                                                <?php }}?>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="modal-footer">
                                    <button type="submit" class="btn btn-primary">保存</button>
                                    <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
        <nav><ul class="pagination justify-content-center"><?php echo $pagination; ?></ul></nav>
    </div>
</div>
<!-- Modal -->
<div class="modal" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg modal-dialog-centered" role="document">
        <div class="modal-content">
            <div class="modal-body">
                <div style="max-height:400px; overflow:auto; " id="precontent"></div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>

<?php include _include(ADMIN_PATH.'view/htm/footer.inc.htm');?>


<script>
    $(function(){
        $("#idcheck").click(function() {
            if (this.checked){
                $("input[name='ids[]']:checkbox").each(function(){
                    $(this).attr("checked", true);
                });
            } else {
                $("input[name='ids[]']:checkbox").each(function() {
                    $(this).attr("checked", false);
                });
            }
        });
    })
    function showpre(id){
        $('#precontent').html($('#'+id).html());
        $('#exampleModal').modal('show');
    }
    $('.option').click(function(){
        var option = $(this).val();
        $('#importType').val(option);
        if(option== 'import' || option == 'importall') {
            $('#importData').modal('show');
        } else {
            if (confirm('你确认执行该操作嘛？')==true){
                return true;
            }else{
                return false;
            }
        }
        return false;
    })

    $('#nav li.nav-item-collection').addClass('active');
</script>